<template>
  <div class="login">
    <div>
      <div class="cancel" @click="goback">
        <img src="../../public/images/x.png" alt="" />
      </div>
      <div class="taptap">
        <img src="../../public/images/taptap.png" alt="" />
      </div>
      <div class="field">
        <div class="tel">
          <div class="cn"><span>CN+86</span><i></i><em></em></div>
          <van-cell @touchstart.stop="show = true"
            ><input type="number" v-model="textValue"
          /></van-cell>
        </div>
        <h6>未注册用户验证后将自动注册并登录</h6>
        <button @click="tohome">登录</button>
        <div class="frame">
          <input type="checkbox" class="check" />
          我已详细阅读并同意TapTap <a href="javascript:;">服务协议</a
          ><a href="javascript:;">隐私协议</a>
        </div>
      </div>
      <div class="weixin">
        <img src="../../public/images/weixin.png" alt="" class="weixinimg" />
        <img src="../../public/images/qq.png" alt="" />
      </div>
    </div>
    <p>社交帐号登录</p>
    <van-number-keyboard
      :show="show"
      @blur="onBlur"
      @input="onInput"
      @delete="onDelete"
    />
  </div>
</template>

<script>
import { ref } from "vue";
import { useRouter } from "vue-router";
import { Toast } from "vant";
export default {
  setup() {
    const show = ref(false);
    const router = useRouter();
    const textValue = ref("");
    let telnameflat = false;
    const onInput = (value) => {
      textValue.value += value;
    };
    const onBlur = () => {
      show.value = false;
      if (textValue.value !== "") {
        let reg = /^1[3579]\d{9}$/;
        if (reg.test(textValue.value)) {
          telnameflat = true;
        } else {
          Toast("号码格式有误");
          telnameflat = false;
        }
      } else {
        Toast("号码不能为空");
        telnameflat = false;
      }
    };
    const onDelete = () =>
      (textValue.value = textValue.value.substring(
        0,
        textValue.value.length - 1
      ));
    const tohome = () => {
      if (telnameflat) {
        if (document.querySelector(".check").checked) {
          localStorage.setItem("tel", textValue.value);
          Toast("注册成功");
          router.push("/home/index");
        } else {
          Toast("请勾选协议");
        }
      } else {
        Toast("号码有误");
      }
    };
    const goback = () => {
      router.push("/home/index");
    };
    return {
      show,
      onInput,
      onDelete,
      onBlur,
      textValue,
      telnameflat,
      tohome,
      goback,
    };
  },
};
</script>
<style lang="less" scoped>
.login {
  .cancel {
    position: fixed;
    left: 17px;
    top: 23.5px;
    img {
      width: 14px;
      height: 14px;
    }
  }
  .taptap {
    position: fixed;
    left: 115px;
    top: 75px;
    img {
      width: 145px;
      height: 43px;
    }
  }
  .weixin {
    position: fixed;
    left: 111.5px;
    bottom: 42px;
    img {
      width: 42px;
      height: 42px;
    }
    .weixinimg {
      margin-right: 68px;
    }
  }
  p {
    position: fixed;
    left: 143px;
    bottom: 100px;
    width: 89px;
    height: 14px;
    font-size: 14px;
  }
  .field {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    top: 167.5px;
    width: 264.5px;
    .tel {
      position: relative;
      .van-cell {
        padding: 0;
      }
      .cn {
        position: absolute;
        top: 50%;
        z-index: 99;
        transform: translateY(-50%);
        left: 9.5px;
        span {
          font-size: 14px;
          color: #333333;
          display: inline-block;
          width: 45px;
          height: 11px;
        }
        i {
          width: 0px;
          height: 0px;
          display: inline-block;
          border: 5px solid #999;
          border-left-color: transparent;
          border-right-color: transparent;
          border-bottom-color: transparent;
          position: absolute;
          top: 13px;
          left: 52px;
        }
        em {
          position: absolute;
          width: 1px;
          height: 21px;
          background: #dfdfdf;
          display: inline-block;
          left: 73px;
          top: 50%;
          transform: translateY(-50%);
        }
      }
      input {
        width: 100%;
        height: 48px;
        font-size: 16px;
        background: #f8f8f8;
        border: 0;
        text-indent: 90px;
        padding: 0;
      }
    }
    h6 {
      font-weight: 400;
      font-size: 13px;
      color: #999999;
      margin-top: 19px;
    }
    button {
      width: 100%;
      height: 45px;
      background: #13b9c7;
      border: 0;
      border-radius: 5px;
      margin-top: 47px;
      color: #fff;
    }
    .frame {
      display: flex;
      align-items: center;
      font-size: 12px;
      height: 14px;
      width: 300px;
      margin-top: 14px;
      input {
        width: 12px;
        height: 12px;
        margin-right: 7px;
      }
    }
  }
}
</style>
